/**
 * @param {number[]} nums
 * @param {number} target
 * @return {number}
 */
 var purchasePlans = function(nums, target) {
    const mod = Math.pow(10,9) + 7
    nums.sort((a,b) => a-b)
    let i = 0, j = nums.length-1, count = 0
    while(i < nums.length-1){
        if(nums[i] + nums[i+1] > target)
            break
        if(nums[i] + nums[j] > target)
            j--
        else{
            count += j-i
            i++
            j = nums.length-1
        }
    }
    return count%mod
};